package com.ruoyi.parttime.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.parttime.domain.ParttimePublish;
import com.ruoyi.parttime.service.IParttimePublishService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 兼职发布Controller
 *
 * @author ruoyi
 * @date 2024-04-02
 */
@RestController
@RequestMapping("/system/publish")
@Api(tags = "兼职发布")
public class ParttimePublishController extends BaseController {
    @Autowired
    private IParttimePublishService parttimePublishService;

    /**
     * 查询兼职发布列表
     */
    @PreAuthorize("@ss.hasPermi('system:publish:list')")
    @ApiOperation(value = "查询本人发布的兼职信息")
    @GetMapping("/list")
    public TableDataInfo list(ParttimePublish parttimePublish) {
        startPage();
        List<ParttimePublish> list = parttimePublishService.selectParttimePublishList(parttimePublish);
        return getDataTable(list);
    }

    /**
     * 导出兼职发布列表
     */
    @PreAuthorize("@ss.hasPermi('system:publish:export')")
    @Log(title = "兼职发布", businessType = BusinessType.EXPORT)
    @ApiOperation(value = "导出本人发布的兼职信息")
    @PostMapping("/export")
    public void export(HttpServletResponse response, ParttimePublish parttimePublish) {
        List<ParttimePublish> list = parttimePublishService.selectParttimePublishList(parttimePublish);
        ExcelUtil<ParttimePublish> util = new ExcelUtil<ParttimePublish>(ParttimePublish.class);
        util.exportExcel(response, list, "兼职发布数据");
    }

    /**
     * 获取兼职发布详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:publish:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(parttimePublishService.selectParttimePublishById(id));
    }

    /**
     * 新增兼职发布
     */
    @PreAuthorize("@ss.hasPermi('system:publish:add')")
    @Log(title = "兼职发布", businessType = BusinessType.INSERT)
    @ApiOperation(value = "发布兼职")
    @PostMapping
    public AjaxResult add(@RequestBody ParttimePublish parttimePublish) {
        return toAjax(parttimePublishService.insertParttimePublish(parttimePublish));
    }

    /**
     * 修改兼职发布
     */
    @PreAuthorize("@ss.hasPermi('system:publish:edit')")
    @Log(title = "兼职发布", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "修改已发布兼职信息")
    @PutMapping
    public AjaxResult edit(@RequestBody ParttimePublish parttimePublish) {
        return toAjax(parttimePublishService.updateParttimePublish(parttimePublish));
    }

    /**
     * 撤销兼职发布
     */
    @PreAuthorize("@ss.hasPermi('system:publish:remove')")
    @Log(title = "兼职发布", businessType = BusinessType.DELETE)
    @ApiOperation(value = "撤销发布的兼职")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(parttimePublishService.deleteParttimePublishByIds(ids));
    }
}
